<script src="#(CPATH)/static/components/vditor/dist/index.min.js"></script>
<script>
    function initVdtior(id, height) {
        height = height || 600;
        var toolbar = [
            "emoji",
            "headings",
            "bold",
            "italic",
            "strike",
            "link",
            "|",
            "list",
            "ordered-list",
            "check",
            "outdent",
            "indent",
            "|",
            "quote",
            "line",
            "code",
            "inline-code",
            "insert-before",
            "insert-after",
            "|",
            "upload",
            "record",
            "table",
            "|",
            "undo",
            "redo",
            "|",
            "fullscreen",
            "edit-mode",
            {
                name: "more",
                toolbar: [
                    "both",
                    "code-theme",
                    "content-theme",
                    "export",
                    "outline",
                    // "preview",
                ],
            }]

        window.currentVditor = new Vditor(id, {
            "cdn": jpress.cpath + "/static/components/vditor",
            "height": height,
            "toolbar": toolbar,
            "upload": {
                url: jpress.cpath + "/commons/vditor/upload",
            },
            "cache": {
                "enable": false
            },
            preview: {
                actions: ["desktop"],
            },
            fullscreen: {
                index: 9999,
            },
            "mode": "wysiwyg",
            // "value": content
        })
    }

    initVdtior('editor');


    window.insertImageToEditor = function (src, title) {
        currentVditor.insertValue('附件：[' + title + '](' + src + ')')
    }

    window.insertVideoToEditor = function (src, title) {
        currentVditor.insertValue('附件：[' + title + '](' + src + ')')
    }

    window.insertAttachementToEditor = function (src, title) {
        currentVditor.insertValue('附件：[' + title + '](' + src + ')')
    }

    window.insertHtmlToEditor = function (html) {
        // currentVditor.insertValue('附件：[' + layer.data.title + '](' + src + ')')
    }

    window.onEditorSubmitBefore = function () {
        $("#content").val(window.currentVditor.getValue());
    }
</script>